
def set_jmp(val,block, blockNumber) :
    lstr = list(block)
    lstr[0:0+3]= val 
    writeBlock(blockNumber, block)

def get_jmp(str) :
    return str[0:0+3]

def set_oem(val,block, blockNumber) :
    lstr = list(block)
    lstr[3:3+8]= val 
    writeBlock(blockNumber, block)

def get_oem(str) :
    return str[3:3+8]

def set_bytes_per_sector(val,block, blockNumber) :
    lstr = list(block)
    lstr[11:13]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_bytes_per_sector(str) :
    return ntoh(str[11:13],2)

def set_sectors_per_cluster(val,block, blockNumber) :
    lstr = list(block)
    lstr[13:14]= hton(val,1) 
    writeBlock(blockNumber, block)

def get_sectors_per_cluster(str) :
    return ntoh(str[13:14],1)

def set_reserved_sectors(val,block, blockNumber) :
    lstr = list(block)
    lstr[14:16]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_reserved_sectors(str) :
    return ntoh(str[14:16],2)

def set_fat_count(val,block, blockNumber) :
    lstr = list(block)
    lstr[16:17]= hton(val,1) 
    writeBlock(blockNumber, block)

def get_fat_count(str) :
    return ntoh(str[16:17],1)

def set_max_root_dirs(val,block, blockNumber) :
    lstr = list(block)
    lstr[17:19]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_max_root_dirs(str) :
    return ntoh(str[17:19],2)

def set_total_sectors_1(val,block, blockNumber) :
    lstr = list(block)
    lstr[19:21]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_total_sectors_1(str) :
    return ntoh(str[19:21],2)

def set_media_descriptor(val,block, blockNumber) :
    lstr = list(block)
    lstr[21:22]= hton(val,1) 
    writeBlock(blockNumber, block)

def get_media_descriptor(str) :
    return ntoh(str[21:22],1)

def set_sectors_per_fat_12_16(val,block, blockNumber) :
    lstr = list(block)
    lstr[22:24]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_sectors_per_fat_12_16(str) :
    return ntoh(str[22:24],2)

def set_sectors_per_track(val,block, blockNumber) :
    lstr = list(block)
    lstr[24:26]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_sectors_per_track(str) :
    return ntoh(str[24:26],2)

def set_number_of_heads(val,block, blockNumber) :
    lstr = list(block)
    lstr[26:28]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_number_of_heads(str) :
    return ntoh(str[26:28],2)

def set_hidden_sectors(val,block, blockNumber) :
    lstr = list(block)
    lstr[28:32]= hton(val,4) 
    writeBlock(blockNumber, block)

def get_hidden_sectors(str) :
    return ntoh(str[28:32],4)

def set_total_sectors_2(val,block, blockNumber) :
    lstr = list(block)
    lstr[32:36]= hton(val,4) 
    writeBlock(blockNumber, block)

def get_total_sectors_2(str) :
    return ntoh(str[32:36],4)

def set_sectors_per_fat_32(val,block, blockNumber) :
    lstr = list(block)
    lstr[36:40]= hton(val,4) 
    writeBlock(blockNumber, block)

def get_sectors_per_fat_32(str) :
    return ntoh(str[36:40],4)

def set_flags(val,block, blockNumber) :
    lstr = list(block)
    lstr[40:42]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_flags(str) :
    return ntoh(str[40:42],2)

def set_version(val,block, blockNumber) :
    lstr = list(block)
    lstr[42:44]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_version(str) :
    return ntoh(str[42:44],2)

def set_root_start_cluster(val,block, blockNumber) :
    lstr = list(block)
    lstr[44:48]= hton(val,4) 
    writeBlock(blockNumber, block)

def get_root_start_cluster(str) :
    return ntoh(str[44:48],4)

def set_fs_info_sector(val,block, blockNumber) :
    lstr = list(block)
    lstr[48:50]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_fs_info_sector(str) :
    return ntoh(str[48:50],2)

def set_boot_sector_copy(val,block, blockNumber) :
    lstr = list(block)
    lstr[50:52]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_boot_sector_copy(str) :
    return ntoh(str[50:52],2)

def set_reserved(val,block, blockNumber) :
    lstr = list(block)
    lstr[52:52+12]= val 
    writeBlock(blockNumber, block)

def get_reserved(str) :
    return str[52:52+12]

def set_drive_number(val,block, blockNumber) :
    lstr = list(block)
    lstr[64:65]= hton(val,1) 
    writeBlock(blockNumber, block)

def get_drive_number(str) :
    return ntoh(str[64:65],1)

def set_reserved1(val,block, blockNumber) :
    lstr = list(block)
    lstr[65:66]= hton(val,1) 
    writeBlock(blockNumber, block)

def get_reserved1(str) :
    return ntoh(str[65:66],1)

def set_ex_boot_sig(val,block, blockNumber) :
    lstr = list(block)
    lstr[66:67]= hton(val,1) 
    writeBlock(blockNumber, block)

def get_ex_boot_sig(str) :
    return ntoh(str[66:67],1)

def set_serial_number(val,block, blockNumber) :
    lstr = list(block)
    lstr[67:71]= hton(val,4) 
    writeBlock(blockNumber, block)

def get_serial_number(str) :
    return ntoh(str[67:71],4)

def set_volume_label(val,block, blockNumber) :
    lstr = list(block)
    lstr[71:71+11]= val 
    writeBlock(blockNumber, block)

def get_volume_label(str) :
    return str[71:71+11]

def set_fs_type(val,block, blockNumber) :
    lstr = list(block)
    lstr[82:82+8]= val 
    writeBlock(blockNumber, block)

def get_fs_type(str) :
    return str[82:82+8]

def set_boot_code(val,block, blockNumber) :
    lstr = list(block)
    lstr[90:90+420]= val 
    writeBlock(blockNumber, block)

def get_boot_code(str) :
    return str[90:90+420]

def set_boot_sector_sig(val,block, blockNumber) :
    lstr = list(block)
    lstr[510:512]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_boot_sector_sig(str) :
    return ntoh(str[510:512],2)

def dumpFatInfo(args) : 
    b0 = block(0)
    output.write("-------------------------------\n")
    output.write("Dumping Fat info...\n")
    output.write("    " + "jmp=<<%s>>"%get_jmp(b0) + "\n")
    output.write("    " + "jmp=(hex)<<%s>>" %" ".join([hex(ord(x)) for x in get_jmp(b0)]) + "\n")
    output.write("    " + "oem=<<%s>>"%get_oem(b0) + "\n")
    output.write("    " + "oem=(hex)<<%s>>" %" ".join([hex(ord(x)) for x in get_oem(b0)]) + "\n")
    output.write("    " + "bytes_per_sector=%d" % get_bytes_per_sector(b0) + "\n")
    output.write("    " + "sectors_per_cluster=%d" % get_sectors_per_cluster(b0) + "\n")
    output.write("    " + "reserved_sectors=%d" % get_reserved_sectors(b0) + "\n")
    output.write("    " + "fat_count=%d" % get_fat_count(b0) + "\n")
    output.write("    " + "max_root_dirs=%d" % get_max_root_dirs(b0) + "\n")
    output.write("    " + "total_sectors_1=%d" % get_total_sectors_1(b0) + "\n")
    output.write("    " + "media_descriptor=%d" % get_media_descriptor(b0) + "\n")
    output.write("    " + "sectors_per_fat_12_16=%d" % get_sectors_per_fat_12_16(b0) + "\n")
    output.write("    " + "sectors_per_track=%d" % get_sectors_per_track(b0) + "\n")
    output.write("    " + "number_of_heads=%d" % get_number_of_heads(b0) + "\n")
    output.write("    " + "hidden_sectors=%d" % get_hidden_sectors(b0) + "\n")
    output.write("    " + "total_sectors_2=%d" % get_total_sectors_2(b0) + "\n")
    output.write("    " + "sectors_per_fat_32=%d" % get_sectors_per_fat_32(b0) + "\n")
    output.write("    " + "flags=%d" % get_flags(b0) + "\n")
    output.write("    " + "version=%d" % get_version(b0) + "\n")
    output.write("    " + "root_start_cluster=%d" % get_root_start_cluster(b0) + "\n")
    output.write("    " + "fs_info_sector=%d" % get_fs_info_sector(b0) + "\n")
    output.write("    " + "boot_sector_copy=%d" % get_boot_sector_copy(b0) + "\n")
    output.write("    " + "reserved=<<%s>>"%get_reserved(b0) + "\n")
    output.write("    " + "reserved=(hex)<<%s>>" %" ".join([hex(ord(x)) for x in get_reserved(b0)]) + "\n")
    output.write("    " + "drive_number=%d" % get_drive_number(b0) + "\n")
    output.write("    " + "reserved1=%d" % get_reserved1(b0) + "\n")
    output.write("    " + "ex_boot_sig=%d" % get_ex_boot_sig(b0) + "\n")
    output.write("    " + "serial_number=%d" % get_serial_number(b0) + "\n")
    output.write("    " + "volume_label=<<%s>>"%get_volume_label(b0) + "\n")
    output.write("    " + "volume_label=(hex)<<%s>>" %" ".join([hex(ord(x)) for x in get_volume_label(b0)]) + "\n")
    output.write("    " + "fs_type=<<%s>>"%get_fs_type(b0) + "\n")
    output.write("    " + "fs_type=(hex)<<%s>>" %" ".join([hex(ord(x)) for x in get_fs_type(b0)]) + "\n")
    output.write("    " + "boot_sector_sig=%d" % get_boot_sector_sig(b0) + "\n")
    output.write("    " + "boot_sector_sig(hex)=<<%x,%x>>" % (ord(b0[510]), ord(b0[511])) + "\n")

def set_file_name(val,block, blockNumber) :
    lstr = list(block)
    lstr[0:0+8]= val 
    writeBlock(blockNumber, block)

def get_file_name(str) :
    return str[0:0+8]

def set_file_ext(val,block, blockNumber) :
    lstr = list(block)
    lstr[8:8+3]= val 
    writeBlock(blockNumber, block)

def get_file_ext(str) :
    return str[8:8+3]

def set_file_attributes(val,block, blockNumber) :
    lstr = list(block)
    lstr[11:12]= hton(val,1) 
    writeBlock(blockNumber, block)

def get_file_attributes(str) :
    return ntoh(str[11:12],1)

def set_dir_reserved(val,block, blockNumber) :
    lstr = list(block)
    lstr[12:13]= hton(val,1) 
    writeBlock(blockNumber, block)

def get_dir_reserved(str) :
    return ntoh(str[12:13],1)

def set_create_time_fine(val,block, blockNumber) :
    lstr = list(block)
    lstr[13:14]= hton(val,1) 
    writeBlock(blockNumber, block)

def get_create_time_fine(str) :
    return ntoh(str[13:14],1)

def set_create_time(val,block, blockNumber) :
    lstr = list(block)
    lstr[14:16]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_create_time(str) :
    return ntoh(str[14:16],2)

def set_create_date(val,block, blockNumber) :
    lstr = list(block)
    lstr[16:18]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_create_date(str) :
    return ntoh(str[16:18],2)

def set_last_access_date(val,block, blockNumber) :
    lstr = list(block)
    lstr[18:20]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_last_access_date(str) :
    return ntoh(str[18:20],2)

def set_high_cluster_bytes(val,block, blockNumber) :
    lstr = list(block)
    lstr[20:22]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_high_cluster_bytes(str) :
    return ntoh(str[20:22],2)

def set_last_modified_time(val,block, blockNumber) :
    lstr = list(block)
    lstr[22:24]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_last_modified_time(str) :
    return ntoh(str[22:24],2)

def set_last_modified_date(val,block, blockNumber) :
    lstr = list(block)
    lstr[24:26]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_last_modified_date(str) :
    return ntoh(str[24:26],2)

def set_low_cluster_bytes(val,block, blockNumber) :
    lstr = list(block)
    lstr[26:28]= hton(val,2) 
    writeBlock(blockNumber, block)

def get_low_cluster_bytes(str) :
    return ntoh(str[26:28],2)

def set_file_size(val,block, blockNumber) :
    lstr = list(block)
    lstr[28:32]= hton(val,4) 
    writeBlock(blockNumber, block)

def get_file_size(str) :
    return ntoh(str[28:32],4)

def dumpDirEntryInfo(args) : 
    b0 = args
    output.write("-------------------------------\n")
    output.write("Dumping DirEntry info...\n")
    output.write("    " + "file_name=<<%s>>"%get_file_name(b0) + "\n")
    output.write("    " + "file_name=(hex)<<%s>>" %" ".join([hex(ord(x)) for x in get_file_name(b0)]) + "\n")
    output.write("    " + "file_ext=<<%s>>"%get_file_ext(b0) + "\n")
    output.write("    " + "file_ext=(hex)<<%s>>" %" ".join([hex(ord(x)) for x in get_file_ext(b0)]) + "\n")
    output.write("    " + "file_attributes=%d" % get_file_attributes(b0) + "\n")
    output.write("    " + "dir_reserved=%d" % get_dir_reserved(b0) + "\n")
    output.write("    " + "create_time_fine=%d" % get_create_time_fine(b0) + "\n")
    output.write("    " + "create_time=%d" % get_create_time(b0) + "\n")
    output.write("    " + "create_date=%d" % get_create_date(b0) + "\n")
    output.write("    " + "last_access_date=%d" % get_last_access_date(b0) + "\n")
    output.write("    " + "high_cluster_bytes=%d" % get_high_cluster_bytes(b0) + "\n")
    output.write("    " + "last_modified_time=%d" % get_last_modified_time(b0) + "\n")
    output.write("    " + "last_modified_date=%d" % get_last_modified_date(b0) + "\n")
    output.write("    " + "low_cluster_bytes=%d" % get_low_cluster_bytes(b0) + "\n")
    output.write("    " + "file_size=%d" % get_file_size(b0) + "\n")
